@echo off

setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

set CHERE_SHELL=d:\zerox\bin\puttycyg\putty.exe
set CHERE_OPTS=-load cygwin
set CYGWIN_INVOKE=d:\bin\cygwin\cygwin.bat

:: cygwin here script
if x%~1==x (set DEST="%CD%") else (set DEST="%*")

set OLD_DIR=%CD%

cd /d %DEST%
if errorlevel 1 goto invalid_dir

echo CD: %CD%
echo %CD% > %HOME%\_autocd
start "" %CHERE_SHELL% %CHERE_OPTS%
REM start "" %CYGWIN_INVOKE%
cd /d "%OLD_DIR%"

:end
goto :eof

:invalid_dir
echo error: %*: cannot chdir
pause
goto :eof

:noarg
echo usage %0 PATH 1>&2
pause
goto :eof

:: vim: set sw=2 et si:
